home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / bootstrap / bootscan.lex < prev    next >
Encoding:
Text File  |  1993-04-16  |  2.9 KB  |  158 lines

  1. %{
  2. static    char    ami_lexer_l[] = "$Header: /private/postgres/src/bootstrap/RCS/bootscanner.lex,v 1.2 1991/11/05 05:31:14 mer Exp $";
  3. /**********************************************************************
  4.  
  5.   ami_lexer. 
  6.  
  7.   a lexical scanner for postgres' amiint
  8.   recent extensions include $def for macro definitions
  9.   and ${id} for macro evaluation
  10.  
  11.  **********************************************************************/
  12.  
  13. #include "support/bkint.h"
  14. #include "tmp/portal.h" 
  15.  
  16. #undef BOOTSTRAP
  17. #include "y.tab.h"
  18.  
  19. #ifdef linux
  20. static int yylineno;
  21. #undef yywrap
  22. #endif
  23. int    yylval;
  24. int yycolumn,yyline;
  25. #define NEWLINE() {yycolumn=0;yyline++;}
  26.  
  27. %}
  28.  
  29. %a 5000
  30. %o 10000
  31.  
  32. D    [0-9]
  33. oct     \\{D}{D}{D}
  34. Exp    [Ee][-+]?{D}+
  35. id      ([A-Za-z0-9_]|{oct}|\-)+
  36. sid     \"([^\"])*\"
  37.  
  38. %%
  39.  
  40. o |
  41. open           return(OPEN);
  42.  
  43. c |
  44. close        return(XCLOSE);
  45.  
  46. C |
  47. create        return(XCREATE);
  48.  
  49. p |
  50. print        return(P_RELN);
  51.  
  52. in        return(XIN);
  53. as        return(AS);
  54. to        return(XTO);
  55. OID             return(OBJ_ID);
  56. bootstrap    return(BOOTSTRAP); 
  57. _null_        return(NULLVAL);
  58.  
  59. i |
  60. insert        return(INSERT_TUPLE);
  61.  
  62. q |
  63. quit        return(QUIT);
  64.  
  65. \%pstr          {printstrtable();EMITPROMPT;}
  66.  
  67. \%phash         {printhashtable();EMITPROMPT;}
  68.  
  69. ".D" |
  70. destroy        {return(XDESTROY);}
  71.  
  72. ".R" |
  73. rename        {return(XRENAME);}
  74. attribute    {return(ATTR);}
  75. relation     {return(RELATION); }
  76. ","         {return(COMMA);}
  77. ":"        {return(COLON);}
  78. "="        {return(EQUALS);}
  79. "("        {return(LPAREN);}
  80. ")"        {return(RPAREN);}
  81. add        {return(ADD);}
  82.  
  83. [\n]          {yylineno++;NEWLINE()};
  84. [\t]        ;
  85. " "        ; 
  86.  
  87. ^\#[^\n]*     yylineno++; /*drop everything after "#" for comments */
  88.  
  89.  
  90. "define"    {return(XDEFINE);}
  91. "macro"        {return(MACRO);}
  92. "index"        {return(INDEX);}
  93. "on"        {return(ON);}
  94. "using"        {return(USING);}
  95. "display"    {return(DISPLAY);}
  96. "show"        {return(SHOW);}
  97. "$"{id}        { 
  98.           char *in, *out, copy[100];
  99.           for(in=out=yytext; *out = *in; out++)
  100.             if(*in++ == '\\') *out = (unsigned char)MapEscape(&in);
  101.           /*
  102.            * The next statement is completely unnecessary (the string
  103.            * copied to out is already null terminated), but it will
  104.            * break the flex scanner (where yytext is just a pointer
  105.            * into flex's input buffer).
  106.            */
  107.           /* *(out+1) = '\000'; */
  108.           yylval=LookUpMacro(&(yytext[1]));
  109.           return(ID);}
  110. {id}          { 
  111.           char *in, *out, copy[100];
  112.           for(in = out = yytext; *out = *in; out++)
  113.             if(*in++ == '\\') *out = (unsigned char)MapEscape(&in);
  114.            /* *(out+1) = '\000'; */
  115.            yylval=EnterString(yytext); return(ID);}
  116. {sid}         {
  117.              char *in;
  118.           for (in = yytext + 1; *in != '\"'; ++in);
  119.           *in = 0;
  120.           yylval=EnterString(yytext+1); return(ID);}
  121.  
  122.  
  123.  
  124. (-)?{D}+"."{D}*({Exp})?    |
  125. (-)?{D}*"."{D}+({Exp})?    |
  126. (-)?{D}+{Exp}        {
  127.              yylval=EnterString(yytext);
  128.              return(FLOAT);
  129.             }
  130.  
  131.  
  132. (-)?{D}+    {
  133.          yylval=EnterString(yytext);
  134.          return(INT);
  135.         }
  136.  
  137.  
  138. .    printf("syntax error %d : -> %s\n", yylineno, yytext);
  139.  
  140.  
  141.  
  142. %%
  143.  
  144. yywrap()
  145. {
  146.     StartTransactionCommand();
  147.     cleanup();
  148.     CommitTransactionCommand();
  149.     return;
  150. }
  151.  
  152. yyerror(str)
  153.     char *str;
  154. {
  155.     fprintf(stderr,"\tsyntax error %d : %s",yylineno, str);
  156. }
  157.  
  158.